import 'package:flutter/material.dart';

class MessageHelper {
  static Future<bool> Confrim(
      BuildContext context, String title, String message) async {
    var result = await showDialog(
        context: context,
        builder: (context) {
          return AlertDialog(
            title: Text(title),
            content: Text(message),
            actions: <Widget>[
              TextButton(
                  child: Text(
                    '取消',
                    style: TextStyle(color: Colors.grey),
                  ),
                  onPressed: () {
                    Navigator.pop(context, false);
                  }),
              TextButton(
                child: Text(
                  '确定',
                  style: TextStyle(color: Colors.blue),
                ),
                onPressed: () {
                  Navigator.pop(context, true);
                },
              ),
            ],
          );
        });
    result ??= false;
    return result as bool;
  }

  static Future<int> Select(
      BuildContext context, String title, List<String> choices) async {
    var children = <Widget>[];
    for(var i = 0;i < choices.length;i++){
      children.add(
        SimpleDialogOption(
          child: Text(choices[i]),
          onPressed: () {
            Navigator.pop(context, i);
          },
        ),
      );
      if(i != choices.length -1){
        children.add(Divider());
      }
    }
    var result = await showDialog(
        context: context,
        builder: (context) {
          return SimpleDialog(
            title: Text(title),
            children:children,
          );
        });
    result ??= -1;
    return result as int;
  }
}
